<template>
  <van-field
    v-if="type === 'config-mobile' || type === 'mobile'"
    v-model="input"
    :placeholder="config.placeholder"
    type="number"
    :required="config.required"
  >
    <template #label>
      <span>{{ config.title }}</span>
    </template>
    <template #right-icon>
      <span>{{ config.suffix }}</span>
    </template>
  </van-field>
  <div v-if="type === 'config-table' || type === 'table'" class="v-form-item-wrapper">
    <div class="form-item">
      <div v-if="config.prefix" class="prefix">{{ config.prefix }}</div>
      <el-input-number
        v-model="input"
        :placeholder="config.placeholder"
        controls-position="right"
        @change="onChange"
      />
      <div v-if="config.suffix" class="suffix">{{ config.suffix }}</div>
      <div v-if="config.required" class="required">*</div>
    </div>
    <pre v-if="config.tips"><i class="icon iconfont">&#xe77e;</i>{{ config.tips }}</pre>
  </div>
</template>

<script setup lang="ts">
const emits = defineEmits(['update'])
const props = defineProps<{
  id: string
  tdId: string
  formType: string
  formTypeName: string
  config: any

  type: string // config table mobile print
  formValue: number
}>()
const input = ref<number>()
const onChange = () => {
  if (input.value != undefined) {
    emits('update', input.value)
  }
}
onMounted(() => {
  input.value = props.formValue
})
</script>
